<?php
	error_reporting(0);
	$errorMsg = $_GET['errorMsg'];
?>
<?php include('header.php'); ?>
<aside id="side-nav" class="span3">
<?php include('side.php'); ?>
</aside>

<script type="text/javascript">
	function registerUser()
	{
		var msg = "Registration failure: \n";
		//check fields are populated
		//verify text is appropriate for type
		
		if (valFName() == false)
		{
			msg = msg + "First name must be at least 2 letters. \n";
		}//end if
		
		if (valLName() == false)
		{
			msg = msg + "Last name must be at least 2 letters. \n";
		}//end if
		
		if (valEmail() == false)
		{
			msg = msg + "Email must be in the proper format: name@example.com \n";
		}//end if
		
		if (valUName() == false)
		{
			msg = msg + "Username must be between 4 and 20 characters, and only contain letters and numbers. \n";
		}//end if
		
		if (valPassword() == false)
		{
			msg = msg + "Password must be between 4 and 20 characters, and only contain letters and numbers.";
		}//end if
		
		if (valFName() == true && valLName() == true && valEmail() == true && valUName() == true && valPassword() == true)
		{
			document.getElementById("registerForm").submit();
		}//end if
		else
		{
		alert(""+msg);
		}//end else
	}//end registerUSer()
	
	function valFName()
	{
		var fName = document.getElementById("fNameField").value;
		if (fName == null || fName == "" || fName.length < 2 || fName.length > 20)
		{
			return false;
		}//end if
		else 
		{
			return true;
		}//end else
	}//end valFName
	
	function valLName()
	{
		var lName = document.getElementById("lNameField").value;
		if (lName == null || lName == "" || lName.length < 2 || lName.length > 30)
		{
			return false;
		}//end if
		else 
		{
			return true;
		}//end else
	}//end valLName
	
	function valEmail()
	{
		var email = document.getElementById("emailField").value;
		if (email == null || email == "")
		{
			return false;
		}//end if
		else 
		{
			var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; //yay stack overflow!
			return re.test(email);
		}//end else
	}//end valEmail
	
	function valUName()
	{
		var uName = document.getElementById("uNameField").value;
		if (uName == null || uName == "" )
		{
			return false;
		}//end if
		else 
		{
			var re = /^([a-zA-Z0-9]){4,20}$/;
			return re.test(uName);
		}//end else
	}//end valUsername
	
	function valPassword()
	{
		var password = document.getElementById("passwordField").value;
		if (password == null || password == "")
		{
			return false;
		}//end if
		else 
		{
			var re = /^([a-zA-Z0-9]){4,20}$/;
			return re.test(password);
		}//end else
	}//end valPassword
	
</script>
<div class="span9 content-container">
	<div id="content-window" class="content">
		<form id="registerForm" name="registerForm" action="register.php" method="post">
			<span><label for="fNameField">First Name:<input type="text" name="fNameField" id="fNameField" placeholder="John"></label></span>
			<span><label for="lNameField">Last Name:<input type="text" name="lNameField" id="lNameField" placeholder="Doe"></label></span>
			<span><label for="emailField">Email:<input type="text" name="emailField" id="emailField" placeholder="jdoe@unf.edu"></label></span>
			<span><label for="uNameField">User Name:<input type="text" name="uNameField" id="uNameField" placeholder="JDoe"></label></span>
			<span><label for="passwordField">Password:<input type="password" name="passwordField" id="passwordField" placeholder="Password"></label></span>
		</form>
		<button onclick="registerUser()">Register</button>
		<p id="regError"><?php echo $errorMsg; ?></p>
	</div>
</div>
<?php include('footer.php'); ?>
